package org.fuxia.im.listeners;

import javax.swing.SwingUtilities;

import org.fuxia.im.common.CommonDialog;
import org.fuxia.im.common.MyMessageDialog;
import org.fuxia.im.common.MyMessageDialog.MessageDialogClickHandler;
import org.fuxia.im.core.entries.ECPacket;
import org.fuxia.im.core.listeners.Listener;
import org.fuxia.im.gui.AddedTip;

/**
 * 当有人添加了我为好友，则提示
 * @author FuXia
 *
 */
public class ReceiveAddedListener implements Listener{

	public void trigger(Object param) {
		final ECPacket packet = (ECPacket)param ;
		String imagePath = packet.getParameter("iamgePath") ;
		String nickName = packet.getParameter("nickName") ;
		String userCode = packet.getParameter("userCode") ;
		String sex = packet.getParameter("sex") ;
		String age = packet.getParameter("age") ;
		String address = packet.getParameter("address") ;
		final int status = Integer.parseInt(packet.getParameter("status")) ;
		final String node = packet.getParameter("node") ;
		final String[] friend = {imagePath, nickName, userCode, sex, age, address} ;
		
		SwingUtilities.invokeLater(new Runnable() {
			
			public void run() {
				final MyMessageDialog dialog = CommonDialog.createMessageNotifyWindow(node) ;
				
					dialog.setClickHandler(new MessageDialogClickHandler() {
						
						public void doAction() {
							if(status == 1) {
								AddedTip addedTip = new AddedTip(node, friend, status) ;
								addedTip.setVisible(true) ;
								dialog.dispose() ;
							}else{
								dialog.dispose() ;
							}
						}
					}) ;
				
					
				dialog.setDelay((long)2000000000) ;
				dialog.showDialog() ;
			}
		}) ;
	}
	
}
